package leeon.bbsbrower.views;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class DocNumberDialog extends Dialog {
	
	
	private Text no = null;
	
	private String ret = null;
	private String init = null;
	
	/**
	 * Create the dialog
	 */
	public DocNumberDialog(Shell parentShell, String init) {
		super(parentShell);
		this.init = init;
	}
	
	/**
	 * 获取返回值
	 * @return
	 */
	public String getRet() {
		return this.ret;
	}
	
	/**
	 * Create contents of the dialog
	 * @param parent
	 */
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		container.setLayout(new FillLayout());
		
		no = new Text(container, SWT.BORDER);
		no.setFont(ApplicationWorkbenchWindowAdvisor.listFont);	
		
		no.addKeyListener(new KeyListener() {

			public void keyPressed(KeyEvent e) {
				//回车返回
				if (e.keyCode == 13 || e.keyCode == 16777296) {
					if (no.getText() != null && no.getText().length() != 0) ret = no.getText();
					DocNumberDialog.this.close();
					e.doit = false;	
				}
			}

			public void keyReleased(KeyEvent e) {}
			
		});
		
		no.setFocus();
		if (this.init != null) no.append(this.init);
		
		
		return container;
	}
	
	
    /**
     * 设定窗口的标题和图片
     */
    protected void configureShell(Shell shell) {
    	super.configureShell(shell);
    	shell.setText("序号输入");    	
    }
		
	/**
	 * 去掉下面的button bar
	 */
	protected Control createButtonBar(Composite parent) {
		return null;
	}
	
	/**
	 * Return the initial size of the dialog
	 */
	protected Point getInitialSize() {
		return new Point(100, 60);
	}

}
